<?php
include './include/common.inc.php';
include '../admin/include/comment.class.php';
$comment = new comment();
$action = isset($action) ? $action : 'manage';
$forward = get_forward('/admin/comment.php');
switch ($action)
{
	case 'edit':
		if(isset($_POST['content']))
		{
			if(check_perms('com002')===false)
			{
				$response->alert('您没有权限进行此操作！');
				$response->execute();
			}
			if(!isset($cid))
			{
				$response->alert('请选择要修改的评论');
				$response->execute();
			}
			$res = $comment->edit_comment(array('content'=>$content),$cid);
			if($res === false)
			{
				$response->alert('修改失败');
			}
			else 
			{
				$response->alert('修改成功');
				$response->redirect($forward);
			}
			$response->execute();
		}
		else 
		{
			if(check_perms('com002')===false)
			{
				showmessage('您没有权限进行此操作！');
			}
			if(!isset($cid))
			{
				showmessage('请选择要修改的评论');
			}
			$info = $comment->get_comment_by_id($cid);
			if(!isset($info['commentid']))
			{
				showmessage('您要修改的评论不存在');
			}
			include template('admin', 'comment_edit');
		}
		break;
	case 'pass';
		if(check_perms('com004')===false)
		{
			$response->alert('您没有权限进行此操作！');
			$response->execute();
		}
		if(!isset($cid) || empty($cid))
		{
			$response->alert('请选择要操作的评论');
			$response->execute();
		}
		$params = array(
			'passed'	=>	$vl
		);
		$res = $comment->edit_comment($params,$cid);
		if($res === false)
		{
			$response->alert('操作失败');
		}
		else 
		{
			$response->alert('操作成功');
			$response->script('self.location=self.location');
		}
		$response->execute();
		break;
	case 'del':
		if(check_perms('com003')===false)
		{
			$response->alert('您没有权限进行此操作！');
			$response->execute();
		}
		if(!isset($cid) || empty($cid))
		{
			$response->alert('请选择要删除的评论');
			$response->execute();
		}
		$params = array(
			'status'	=>	STATUS_DEL
		);
		$res = $comment->edit_comment($params,$cid);
		if($res === false)
		{
			$response->alert('删除失败');
		}
		else 
		{
			$response->alert('删除成功');
			$response->script('self.location=self.location');
		}
		$response->execute();
		break;
	case 'delall':
		if(check_perms('com003')===false)
		{
			$response->alert('您没有权限进行此操作！');
			$response->execute();
		}
		if(is_array($ck) && sizeof($ck) > 0)
		{
			$params = array(
				'status'	=>	STATUS_DEL
			);
			foreach ($ck as $k=>$v)
			{
				$comment->edit_comment($params,$v);
			}
			$response->alert('删除成功');
			$response->script('self.location=self.location');
		}
		else 
		{
			$response->alert('请选择要删除评论');
		}
		$response->execute();
		break;
	case 'search':
		$url = $self_url;
		$search_params = array();
		if(isset($passed) && intval($passed) >= 0)
		{
			$search_params[] = 'passed='.$passed;
		}
		if(isset($flag) && intval($flag) >= 0)
		{
			$search_params[] = 'flag='.$flag;
		}
		if(isset($nid) && !empty($nid))
		{
			$search_params[] = 'nid='."'$nid'";
		}
		if(isset($time) && intval($time) >= 0)
		{
			$search_params[] = 'time='.$time;
		}
		if(isset($kw) && !empty($kw))
		{
			$search_params[] = 'kw='.urlencode($kw);
		}
		$pos = sizeof($search_params)>0 ? '?' : '';
		$response->redirect($url.$pos.implode('&',$search_params));
		$response->execute();
		break;
	case 'manage':
	default:
		if(check_perms('com001')===false)
		{
			showmessage('您没有权限进行此操作！');
		}
		$page = isset($page) ? $page : 1;
		$page = max(1,intval($page));
		$pagesize = 20;
		$nid = isset($nid) ? $nid : false;
		$passed = isset($passed) ? $passed : false;
		$kw = isset($kw) ? $kw : false;
		$time = isset($time) ? $time : false;
		$flag = isset($flag) ? $flag : -1;
		$list = $comment->get_comment($page,$pagesize,1,$nid,$passed,$kw,$time);
		$pages = $comment->pages;
		$forward = make_forward();
		include template('admin', 'comment_manage');
		
}
?>